package com.swust.servlet;

import com.swust.service.LibServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddBookServlet",urlPatterns = "/AddBookServlet")
public class AddBookServlet extends HttpServlet {

    private LibServiceImpl libService = new LibServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Long ID = Long.valueOf(request.getParameter("id"));
        String bookName = request.getParameter("bookName");
        String bookClass = request.getParameter("catgoryName");
        int price = Integer.parseInt(request.getParameter("price"));
        String bookInfo = request.getParameter("description");
        libService.addBook(ID,bookName,bookClass,price,bookInfo);
        response.sendRedirect(request.getContextPath() + "/ShowBookServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
